import json
import frappe
from frappe.query_builder import Criterion

# 暂时用不到
@frappe.whitelist()  
def get_item_query(doctype, txt, searchfield, start, page_len, filters):
    item = frappe.qb.DocType("Item")  

    qb_filter_and_conditions = []
    item_codes = filters.get("item_codes")

    if filters and item_codes:
        qb_filter_and_conditions.append(item.item_code.notin(item_codes))
    q=(frappe.qb.from_(item)
        .select(item.name, item.item_name, item.stock_uom,item.description)  
        .where(Criterion.all(qb_filter_and_conditions))
    )

    item_code=filters.get("item_code")
    if filters and item_code:
        q = q.where(item.item_code.like(f"%{item_code}%") | item.item_name.like(f"%{item_code}%") )
	
    if page_len:
        q = q.limit(page_len)

    if start:
        q = q.offset(start)
    
    # print(q)
    return q.run()